const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    longUID:'1329462',
    LoginUID:0,
    banner:'../../images/fbzcbanner.jpg',
    logo:'../../images/wd-headpic.png',
    company:[],
    IsLxfs:0,
    LxBgdh : '',
    LxEmail : '',
    xGsdz : '',
    LxLxdh : '',  
    gszy:[],
    GyList:[],            
    QgList:[],  
    nopic:'../../images/zcczNopic.png',
    showtel:false,  
    tellist:[],      
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.setData({
    //   longUID:options.longUID
    // })
    this.getShopAbout();
    this.getQgList();
    this.getGyList();
    console.log(options)   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getShopAbout:function () {
    var that = this;
    this.setData({
      longUID:this.data.longUID      
    })
    var url = 'api/FeijiuApp/GetShopAbout?longUID='+this.data.longUID+'&LoginUID='+this.data.LoginUID+'&strRSA=';    
    app.getDaoGet(url,function (r) {
      console.log(r)
      if (r.code == 200) {
        wx.setNavigationBarTitle({
          title: r.data.ComName 
        })
        r.data.HyYear = that.tmpnewchar(r.data.HyYear);

        if (r.data.isDeBao == 1) {
          r.data.isDeBaoname = '已认证'
        }else{
          r.data.isDeBaoname = '未认证'
        }
        var desc = r.data.Gszy.split(",");
        if (desc.length < 2) {
          var desc = r.data.Gszy.split("，");
        }

        that.setData({
          LxBgdh : app.aesDec(r.data.LxBgdh),
          LxEmail : app.aesDec(r.data.LxEmail),
          LxGsdz : app.aesDec(r.data.LxGsdz),
          LxLxdh : app.aesDec(r.data.LxLxdh),
          gszy:desc
        })

        that.setData({
          company:r.data,
          IsLxfs:r.data.IsLxfs
        })
      }      
    })
  },
// 把数字1转成一
  tmpnewchar:function (num) {    
    var tmpnewchar = '一';
    switch (num) {     
      case "1": tmpnewchar = "一" ; break;
      case "2": tmpnewchar = "二" ; break;
      case "3": tmpnewchar = "三" ; break;
      case "4": tmpnewchar = "四" ; break;
      case "5": tmpnewchar = "五" ; break;
      case "6": tmpnewchar = "六" ; break;
      case "7": tmpnewchar = "七" ; break;
      case "8": tmpnewchar = "八" ; break;
      case "9": tmpnewchar = "九" ; break;
      case "10": tmpnewchar = "十" ; break;
      case "11": tmpnewchar = "十一" ; break;
      case "12": tmpnewchar = "十二" ; break;
      case "13": tmpnewchar = "十三" ; break;
      case "14": tmpnewchar = "十四" ; break;
      case "15": tmpnewchar = "十五" ; break;
      case "16": tmpnewchar = "十六" ; break;
      case "17": tmpnewchar = "十七" ; break;
      case "18": tmpnewchar = "十八" ; break;
      case "19": tmpnewchar = "十九" ; break;
    }
    return tmpnewchar;
  },  
  //type == 1 供应信息
  //type == 2 求购信息
  getGyList:function () {
    var that = this;
    var url = 'api/FeijiuApp/GetShopGqList?longUID='+this.data.longUID+'&type=1&intCurrPage=1&intPageSize=6&strRSA=';
    app.getDaoGet(url,function (r) {
      if (r.code == 200) {
        for (var i = 0; i < r.data.List.length; i++) {
          var photoss = app.photoSplitOne(r.data.List[i].photo);
          if (photoss == '') {
             r.data.List[i].photoOne = that.data.nopic;
          }else{
             r.data.List[i].photoOne = photoss;
          }
        }
        that.setData({
          GyList:r.data.List
        })
       console.log(r)
      }
    })
  }, 
  getQgList:function () {
    var that = this;
    var url = 'api/FeijiuApp/GetShopGqList?longUID='+this.data.longUID+'&type=2&intCurrPage=1&intPageSize=6&strRSA=';
    app.getDaoGet(url,function (r) {
      if (r.code == 200) {
        for (var i = 0; i < r.data.List.length; i++) {
          var photoss = app.photoSplitOne(r.data.List[i].photo);
          if (photoss == '') {
             r.data.List[i].photoOne = that.data.nopic;
          }else{
             r.data.List[i].photoOne = photoss;
          }
        }
        that.setData({
          QgList:r.data.List
        })
       console.log(r)
      }
    })
  },
  togongying:function () {
    wx.navigateTo({
      url: 'gongying?longUID='+this.data.longUID
    })
  },
  toqiugou:function () {
    wx.navigateTo({
      url: 'qiugou?longUID='+this.data.longUID
    })
  },  
  totel:function () {
  	var tel = this.data.LxLxdh.split(",");
  	console.log(tel);
    this.setData({
    	showtel:true,
    	tellist:tel
    })
  },
  quxiaotel:function () {
  	this.setData({
  		showtel:false,
  	})
  },
  tocall:function (e) {
  	wx.makePhoneCall({
  		phoneNumber: e.currentTarget.dataset.tel,
  		success: (res) => {
  			this.setData({
  				showtel:false,
  			})
  		},
  		fail: (res) => {
  			
  		},
  		complete: (res) => {
  			
  		}
  	})
  }
})